<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>测试密码强度</title>
  </head>
  <body>
    <input type="password" name="password" />
    <span id="span"></span>
    <script>
      document
        .querySelector('[name="password"]')
        .addEventListener("keyup", function () {
          let userPasswordLength = this.value.length;
          let spans = document.querySelector("#span");
          let msg = "";
          if (userPasswordLength > 10) {
            msg = "非常safely";
          } else if (userPasswordLength > 6) {
            msg = "一般safely";
          } else {
            msg = "unsafely";
          }
          spans.innerHTML = msg;
        });

      // 对象传参，三元
      function div(options = {}) {
        let div = document.createElement("div");
        div.style.width = options.width ? options.width : "100px";
        div.style.height = options.height ? options.height : "100px";
        div.style.backgroundColor = options.bgcolor ? options.bgcolor : "red";
        document.body.appendChild(div);
      }
      div({
        width: "50px",
        htigh: "50px",
        bgcolor: "green",
      });
    </script>
  </body>
</html>
